/*
ID:ykzhuji1
PROG:transform
LANG:C++
 */

#include <fstream>
#include <iostream>
using namespace std;
typedef int(*foo)(int,int);
int number;
char** buffer1;
char** buffer2;
int row1(int i,int j){return j;}
int col1(int i,int j){return number-1-i;}
int row2(int i,int j){return row1(row1(i,j),col1(i,j));}
int col2(int i,int j){return col1(row1(i,j),col1(i,j));}
int row3(int i,int j){return row1(row2(i,j),col2(i,j));}
int col3(int i,int j){return col1(row2(i,j),col2(i,j));}
int row4(int i,int j){return i;}
int col4(int i,int j){return number-1-j;}
int row5_1(int i,int j){return row1(row4(i,j),col4(i,j));}
int col5_1(int i,int j){return col1(row4(i,j),col4(i,j));}
int row5_2(int i,int j){return row2(row4(i,j),col4(i,j));}
int col5_2(int i,int j){return col2(row4(i,j),col4(i,j));}
int row5_3(int i,int j){return row3(row4(i,j),col4(i,j));}
int col5_3(int i,int j){return col3(row4(i,j),col4(i,j));}
int row6(int i,int j){return i;}
int col6(int i,int j){return j;}

bool check(foo row, foo col){
	bool ret=true;
	for(int i=0;i<number;i++){
		for(int j=0;j<number;j++){
			if(buffer2[i][j]!=buffer1[row(i,j)][col(i,j)]){
				ret=false;
				break;
			}
		}
	}
	return ret;
}
#define CHECK(i,j) if(check(row##i,col##i))return j;
int checkAll(){
	CHECK(1,1);
	CHECK(2,2);
	CHECK(3,3);
	CHECK(4,4);
	CHECK(5_1,5);
	CHECK(5_2,5);
	CHECK(5_3,5);
	CHECK(6,6);
	return 7;
}
int main(){
	ofstream fout("transform.out");
	ifstream fin("transform.in");
	fin>>number;
	//cin>>number;
	buffer1=new char*[number];
	buffer2=new char*[number];
	for(int i=0;i<number;i++){
		buffer1[i]=new char[number];
		buffer2[i]=new char[number];
	}
	for(int i=0;i<number;i++){
		for(int j=0;j<number;j++){
			fin>>buffer1[i][j];
			//cin>>buffer1[i][j];
		}
	}
	for(int i=0;i<number;i++){
		for(int j=0;j<number;j++){
			fin>>buffer2[i][j];
			//cin>>buffer2[i][j];
		}
	}
	fout<<checkAll()<<endl;
	//cout<<checkAll();
	return 0;
}
